﻿Public Class IconPanel
    Inherits ContentPanel

    Protected mintIconSpacing As Integer
    Protected mintMargin As Integer

    Public ReadOnly Property IconSpacing As Integer
        Get
            Return mintIconSpacing
        End Get
    End Property

    Public Overloads ReadOnly Property Margin As Integer
        Get
            Return mintMargin
        End Get
    End Property


    Public Sub New()
        mintMargin = 10
        mintIconSpacing = 32 + 15 + 10 'icon height + text height + margin
        BackColor = Color.LightBlue
        AutoScroll = True
    End Sub

    Public Sub AddIcon(ByVal caption As String, ByVal image As Image, ByVal onClickEvent As EventHandler)
        Dim index As Integer = Controls.Count / 2  'two entries per icon
        Dim panelIcon As PanelIcon = New PanelIcon(Me, image, index, onClickEvent)
        Controls.Add(panelIcon)

        Dim label As Label = New Label
        label.Text = caption
        label.Visible = True
        label.Location = New Point(0, Margin + image.Size.Height + index * IconSpacing)
        label.Size = New Size(Size.Width, 15)
        label.TextAlign = ContentAlignment.TopCenter
        AddHandler label.Click, onClickEvent
        label.Tag = panelIcon
        Controls.Add(label)
    End Sub

    Private Sub IconPanel_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
        Me.Focus()
    End Sub
End Class
